home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 July: Mac OS SDK / Dev.CD Jul 96 SDK / Dev.CD Jul 96 SDK2.toast / Development Kits (Disc 2) / QuickDraw GX / Programming Stuff / Sample Code / Printing Samples / Applications… / QuickDraw GX Aware Sample ƒ / Simple Sample GX ƒ / Simple Sample.h < prev   
Encoding:
Text File  |  1995-07-12  |  7.4 KB  |  215 lines  |  [TEXT/MMCC]

  1. /*********************************************************************
  2.  
  3.     Simple Sample.h
  4.     
  5.     This is the header file for the QuickDraw GX aware sample,
  6.     "Simple Sample GX."
  7.     
  8.     Additional info can be found in the related develop #19 article,
  9.     "Adding QuickDraw GX Printing to QuickDraw Applications."
  10.  
  11.     Dave Hersey, Apple Developer Technical Support.
  12.     
  13.     ——————— Edit Trail ———————
  14.     
  15.     spawned:                                        1/22/94  - dmh
  16.     cleaned up for 2nd draft of develop article:    3/10/94  - dmh
  17.     cleaned up for final:                            4/14/94  - dmh
  18.     universalized:                                    8/24/94  - dmh
  19.     changed for new GX interfaces:                    7/11/95  - dmh
  20.     
  21. *********************************************************************/
  22.  
  23. //#include <stdio.h>                            // Regular interface files.
  24. #include <AppleEvents.h>
  25. #include <Desk.h>
  26. #include <Events.h>
  27. #include <Files.h>
  28. #include <Fonts.h>
  29. #include <GestaltEqu.h>
  30. #include <Memory.h>
  31. #include <Packages.h>
  32. #include <Quickdraw.h>
  33. #include <Resources.h>
  34. #include <StandardFile.h>
  35. #include <ToolUtils.h>
  36. #include <Types.h>
  37. #include <Windows.h>
  38.  
  39. #include <GXGraphics.h>                        // QuickDraw GX interface files.
  40. #include <GXEnvironment.h>
  41. #include <GXPrinting.h>
  42. #include <GXExceptions.h>                    // some GX headers called this exceptions.h, you may need to rename the file
  43.                                             // in your GX folder from exceptions.h to GXExceptions.h
  44.  
  45. #define    kOSEvent                    app4Evt    /* Event used by MultiFinder                    */
  46. #define    kSuspendResumeMessage        1        /* High byte of suspend/resume event message    */
  47. #define    kResumeMask                    1        /* Bit of message field for resume vs. suspend    */
  48.  
  49. #define        r_About                128            /* Our app's "About…" alert ID.                    */
  50. #define        r_BadConfig            130            /* Our app's "Bad configuration…" alert ID.        */
  51. #define        r_documentPict        128            /* Our PICT's resource ID.                        */
  52. #define        r_documentBitmap    128            /* Our ICON's resource ID.                        */
  53.  
  54. #define        kMyDocCreator        'SSam'        /* Our app's creator.                            */
  55. #define        kMyDocType            'aDoc'        /* Our document file type.                        */
  56. #define        kMyPageCountType    'Pgs?'        /* Our page count resource type.                */
  57. #define        kMyPageCountID        2000        /* Our page count resource ID.                    */
  58. #define        kMyPrintRecType        'THPR'        /* Our print record resource type.                */
  59. #define        kMyPrintRecID        1000        /* Our print record resource ID.                */
  60. #define        kMyJobType            'FJOB'        /* Our gxJob resource type.                        */
  61. #define        kMyJobID            1000        /* Our gxJob resource ID.                        */
  62. #define        kMyFormatInfoType    'FLST'        /* Our format list collection item tag.            */
  63. #define        kMyFormatInfoTagID    1000        /* Our format list collection item ID.            */
  64.  
  65. #define        kGraphicsHeapSize    ((long) 300 * 1024)
  66. #define        kDefaultTitle        ((char *) "\pUntitled Document")
  67.  
  68. // Various PicComments:
  69.  
  70. #define        PostScriptBegin        190
  71. #define        PostScriptEnd        191
  72. #define        PostScriptHandle    192
  73.  
  74.  
  75. /*
  76.     MyDocumentRec - This structure contains information that we store
  77.     about each document we open or create.  We store a handle to one
  78.     of these beasties in each window's refCon field.  Note that the
  79.     MyDocumentRec data type in this example is simplified to handle a
  80.     maximum of 20 pages.
  81. */
  82.  
  83. #define kMaxPages    20
  84.  
  85. typedef struct MyDocumentRec {
  86.         THPrint            documentPrintHdl;            // Print Record bound to this document.
  87.         gxJob            documentJob;                // Job bound to this document.
  88.         gxFormat        pageFormat[kMaxPages];        // format for each page.  If nil, we use
  89.                                                     // the job format.
  90.  
  91.         long            numPages;                    // Number of pages in this document.
  92.         long            curPage;                    // The current page that we're looking at.
  93.         FSSpec            documentFSSpec;                // The file specification for this document.
  94.         Str31            documentTitle;                // The title of this document (such
  95.                                                     // as "Untitled").
  96.         WindowPtr        documentWindow;                // The window for this document.
  97. } MyDocumentRec, *MyDocumentPtr;
  98.  
  99.  
  100. typedef struct MySpoolDataRec {
  101.         gxRectangle        pageArea;                    // Page rectangle.
  102.         gxViewPort        printViewPort;                // ViewPort we're printing with.
  103. } MySpoolDataRec, *MySpoolDataPtr;
  104.  
  105.  
  106. // globals from main.c:
  107.  
  108. extern short                 gAppResRefNum;
  109. extern Rect                 gWindowRect;
  110. extern Boolean                gQuitAfterPrinting, gQuitting, gSystemSevenIsPresent;
  111. extern Boolean                gGXIsPresent, gInPrintDialog;
  112. extern long                    gSleep;
  113. extern gxGraphicsClient        gClient;
  114.  
  115.                     //  Prototypes: //
  116.  
  117. // main.c:
  118.  
  119. void            MyInitialize(void);
  120. void            MyCheckConfig(void);
  121. void            MyInitGXIfPresent(void);
  122. void            MyCleanUpGXIfPresent(void);
  123. OSErr            MyPrintingEventOverride(EventRecord *anEvent, Boolean filterEvent);
  124. void            main(void);
  125.  
  126. // events.c
  127.  
  128. void            MyEventLoop(void);
  129. void            MyDoEvent(EventRecord *theEvent);
  130. void            MyDoAEInstallation(void);
  131. pascal OSErr    MyHandleOAPP(AppleEvent *theAppleEvent, AppleEvent *reply, long myRefCon);
  132. pascal OSErr    MyHandleQUIT(AppleEvent *theAppleEvent, AppleEvent *reply, long myRefCon);
  133. pascal OSErr    MyHandleODOC(AppleEvent *theAppleEvent, AppleEvent *reply, long myRefCon);
  134. pascal OSErr    MyHandlePDOC(AppleEvent *theAppleEvent, AppleEvent *reply, long myRefCon);
  135. OSErr            MyCheckAEParams(AppleEvent *theAppleEvent);
  136.  
  137. // file.c
  138.  
  139. OSErr            MyLoadDocument(MyDocumentPtr whichDocument);
  140. OSErr            MyFSLoadDocument(MyDocumentPtr destDocument, FSSpec *docFSSpec, Boolean forPrinting);
  141. Boolean            MyIsWindowAlreadyOpen(FSSpec *whichFSSpec);
  142. OSErr            MySaveDocument(MyDocumentPtr myDocument, Boolean doingSaveAs);
  143. OSErr            MySavePageCount(MyDocumentPtr whichDocument, short resRefNum);
  144. long            MyLoadPageCount(short resRefNum);
  145. OSErr            MySaveFormatRefs(MyDocumentPtr whichDocument);
  146. OSErr            MyCreateFormatIndexList(MyDocumentPtr whichDocument, Handle *theFormatIdxList);
  147. OSErr            MyAdjustFormats(MyDocumentPtr whichDocument);
  148. OSErr            MySavePrintInfo(MyDocumentPtr whichDocument, short resRefNum);
  149. OSErr            MyLoadPrintInfo(MyDocumentPtr whichDocument, short resRefNum);
  150.  
  151. // menus & windows.c:
  152.  
  153. OSErr            MyCreateDocument(char *title, MyDocumentPtr *createdDocument);
  154. void            MyDisposeDocument(MyDocumentPtr whichDocument);
  155. OSErr            MyInsertPage(MyDocumentPtr whichDocument, long *whichPage);
  156. void            MyDisposePage(MyDocumentPtr whichDocument, long whichPage);
  157. void            MyUpdateWindow(WindowPtr whichWindow);
  158. void            MyDrawContents(WindowPtr whichWindow);
  159. void            MyDrawPicComments(void);
  160. void            MySendPostScript(Str255 thePostScript);
  161. void            MyAdjustMenus(void);
  162. void            MyAdjustMenusForPrintDialogs(Boolean dialogGoingUp);
  163. void            MyDoMenuCommand(long menuResult);
  164. void            MyConvertMenuItem(short *menuID, short *menuItem);
  165. MyDocumentPtr    MyGetDocPtr(WindowPtr whichWindow);
  166.  
  167. // printing.c:
  168.  
  169. OSErr            MyPrintDocument(MyDocumentPtr whichDocument);
  170. OSErr            MyPrintOneCopy(MyDocumentPtr whichDocument);
  171. OSErr            MyQDPrintLoop(MyDocumentPtr whichDocument);
  172. OSErr            MyGXPrintLoop(MyDocumentPtr whichDocument);
  173. OSErr            MyPrintAShape(gxShape currentShape, long refCon);
  174. Boolean            MyDoPageSetup(MyDocumentPtr whichDocument);
  175. Boolean            MyDoCustomPageSetup(MyDocumentPtr whichDocument);
  176. void            MyRepaginateDoc(MyDocumentPtr whichDocument);
  177. OSErr            MyReplaceCollectionItem(void *newData, long collectSize,
  178.                                         OSType collectType, long collectID,
  179.                                         Collection whichCollection,
  180.                                         Ptr *oldData, long *oldDataSize);
  181.  
  182. // resource & menu item equates:
  183.  
  184. #define rMenuBar        128
  185. #define mApple            128
  186. #define     iAbout                1
  187.  
  188. #define mFile            129
  189. #define     iNew                1
  190. #define     iOpen                2
  191. #define     iClose                3
  192. #define     iSave                4
  193. #define     iSaveAs            5
  194. #define     iPageSetup            7
  195. #define     iCustomPageSetup    8
  196. #define     iPrint                9
  197. #define     iPrintOneCopy        10
  198. #define     iQuit                   12
  199.  
  200. #define mEdit            130
  201. #define     iUndo                1
  202. #define     iCut                3
  203. #define     iCopy                4
  204. #define     iPaste                5
  205. #define     iClear                6
  206.  
  207. #define mDocument        131
  208. #define     iInsertPage        1
  209. #define     iDeletePage        2
  210. #define     iAheadPage            4
  211. #define     iBackPage            5
  212.  
  213.  
  214.  
  215.